import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

import layout from '@/views/layout/index'
import MainRouterView from '@/components/MainRouterView'
import { sysRoute } from '@/router/sys'
import { testRoute } from '@/router/testRoute'
import { packagesRoute } from '@/router/packages'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: '/',
    redirect: '/sys',
    component: layout,
    children: [
      {
        path: '/sys',
        name: 'sys',
        redirect: '/sys/user',
        component: MainRouterView,
        children: sysRoute
      },
      {
        path: '/packages',
        name: 'packages',
        redirect: '/packages/card',
        component: MainRouterView,
        children: packagesRoute
      },
      {
        path: '/test',
        name: 'test',
        redirect: '/sys/test',
        component: MainRouterView,
        children: testRoute
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('@/views/Home')
  },
  {
    path: '/:match(.*)*',
    name: '404',
    component: () => import('@/views/error404/404')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
